var router = require('koa-router')();

// import config from '../config';
// -----------资产数据相关接口Start-----------------



//默认打开页面加载全部数据
router.post('/propertyData/getAll',async(ctx,next) =>{
    let{period} = ctx.request.body

    //资产池
    let assetPoolData = await ctx.get('/web/assetData/data/assetDataStatTotal',{period:period});
    //top5
    let topFive = await ctx.get('/web/assetData/data/assetTop5',{period:period});
    //账期分析
    let paymentDaysAnalyze = await ctx.get('/web/assetData/data/billAnalysis',{period:period,type:'1'});
    //集中度分析
    let concentrateAnalyze = await ctx.get('/web/assetData/data/concentrationAnalysis',{period:period,type:'1',pageNumber:'1',pageSize:'10'});
    //地域分析
    let areaAnalyze = await ctx.get('/web/assetData/data/areaAnalysis',{period:period,type:'1',pageNumber:'1',pageSize:'10'});
    //债务人分析
    let debtorAnalyze = await ctx.get('/web/assetData/data/buyerAnalysis',{period:period,type:'1'});
    //货物分析
    let goodsAnalyze = await ctx.get('/web/assetData/data/goodsAnalysis',{period:period,type:'1'});
    //资产分析
    let assetAnalyze = await ctx.get('/web/assetData/data/assetAnalysis',{period:period,type:'1'});

    if (!assetPoolData.success && assetPoolData.message =="User Unauthorized") {
        ctx.body = assetPoolData;
    }else{
        let result = {
            assetPoolData:assetPoolData||{},
            topFive:topFive||{},
            paymentDaysAnalyze:paymentDaysAnalyze||{},
            concentrateAnalyze:concentrateAnalyze||{},
            areaAnalyze:areaAnalyze||{},
            debtorAnalyze:debtorAnalyze||{},
            goodsAnalyze:goodsAnalyze||{},
            assetAnalyze:assetAnalyze || {},
        }

        ctx.body = result;
    }
})

//账期分析
router.post('/getBillAnalysis/list',async(ctx,next) =>{
    let {
        type,
        period
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/data/billAnalysis',{type,period});
    ctx.body = result;
})

//集中度分析
router.post('/getConcentrationAnalysis/list',async(ctx,next) =>{
    let {
        type,
        pageNumber,
        pageSize,
        period
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/data/concentrationAnalysis',{type,pageNumber,pageSize,period});
    ctx.body = result;
})

//地域分析
router.post('/getAreaAnalysis/list',async(ctx,next) =>{
    let{
        type,
        pageNumber,
        pageSize,
        period
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/data/areaAnalysis',{type,pageNumber,pageSize,period});
    ctx.body = result;
})

//债务人分析
router.post('/getBuyerAnalysis/list',async(ctx,next) =>{
    let{
        type,
        period
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/data/buyerAnalysis',{type,period});
    ctx.body = result;
})

//货物分析
router.post('/getGoodsAnalysis/list',async(ctx,next) =>{
    let{
        type,
        period
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/data/goodsAnalysis',{type,period});

    ctx.body = result;
})

//资产分析
router.post('/getAssetAnalysis/list',async(ctx,next) =>{
    let{
        type,
        period
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/data/assetAnalysis',{type,period});

    ctx.body = result;
})




// -----------资产数据相关接口End-----------------

//------------循环购买相关接口Start---------------
//获取全部
router.post('/getCycleBuying/getAll',async(ctx,next) =>{
    let{
        period,
    } = ctx.request.body;
    
    let cycleBuying = await ctx.get('/web/assetData/cycle/cycleBuying',{period});
    let currentRecycle = await ctx.get('/web/assetData/cycle/assetRecycle',{period:period,pageNumber:1,pageSize:10});
    let currentBuying = await ctx.get('/web/assetData/cycle/assetBuying',{period:period,pageNumber:1,pageSize:10});
    if (!cycleBuying.success && cycleBuying.message == "User Unauthorized") {
        ctx.body = cycleBuying;
    }else{
        let result = {
            cycleBuying:cycleBuying||{},
            currentRecycle:currentRecycle||{},
            currentBuying:currentBuying||{},
        }

        ctx.body = result;
    }

})
//循环购买
// router.post('/getCycleBuying',async(ctx,next) =>{
//     let{
//         period,
//     } = ctx.request.body;
//     let result = await ctx.get('/web/assetData/cycle/cycleBuying',{period});
//     console.log('/getCycleBuying-----------',result);
//     ctx.body = result;
// })
//当期回收
router.post('/getCurrentRecycle/list',async(ctx,next) =>{
    let{
        period,
        pageNumber,
        pageSize,
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/cycle/assetRecycle',{period,pageNumber,pageSize});

    ctx.body = result;
})
//当期购买
router.post('/getCurrentBuying/list',async(ctx,next) =>{
    let{
        period,
        pageNumber,
        pageSize,
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/cycle/assetBuying',{period,pageNumber,pageSize});

    ctx.body = result;
})
//------------循环购买相关接口End-----------------

//------------资产报告相关接口Start---------------
//全部
router.post('/getAssetReport/All',async(ctx,next) =>{
    let{
        period,
        type,
    } = ctx.request.body;
    let assetReport = await ctx.get('/web/assetData/report/assetReport',{period});
    let currentHappen = await ctx.get('/web/assetData/cycle/currentHappen',{period});
    let recycleAmount = await ctx.get('/web/assetData/report/recycleAmount',{period,type});
    let endAsset = await ctx.get('/web/assetData/report/endAsset',{period,type});
    let endAccumulate = await ctx.get('/web/assetData/report/endAccumulate',{period});
    if (!assetReport.success && assetReport.message == "User Unauthorized") {
        ctx.body = assetReport;
    }else{
        let result = {
            assetReport:assetReport || {},
            currentHappen:currentHappen || {},
            recycleAmount:recycleAmount || {},
            endAsset:endAsset || {},
            endAccumulate:endAccumulate || {},
        }


        ctx.body =  result;
    }
})
//资产报告
// router.post('/getAssetReport',async(ctx,next) =>{
//     let{
//         period,
//     } = ctx.request.body;
//     let result = await ctx.get('/web/assetData/report/assetReport',{period});
//     console.log('/getAssetReport-----------',result);
//     ctx.body = result;
// })
//当期发生
router.post('/getCurrentHappen/list',async(ctx,next) =>{
    let{
        period,
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/cycle/currentHappen',{period});

    ctx.body = result;
})
//回收款
router.post('/getRecycleAmout/list',async(ctx,next) =>{
    let{
        period,
        type,
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/report/recycleAmount',{period,type});

    ctx.body = result;
})
//期末资产
router.post('/getEndtermAsset/list',async(ctx,next) =>{
    let{
        period,
        type,
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/report/endAsset',{period,type});

    ctx.body = result;
})
//期末累计
router.post('/getEndtermTotal/list',async(ctx,next) =>{
    let{
        period,
    } = ctx.request.body;
    let result = await ctx.get('/web/assetData/report/endAccumulate',{period});

    ctx.body = result;
})
//------------资产报告相关接口End-----------------
//
//获取期数接口
router.post('/getAssetPeriods',async(ctx,next) =>{
    ctx.body = await ctx.get('/web/assetData/assetPeriods',{});
})

export default router;
